<template>
    <el-container class="home_container">
        <!--        头部区域-->
        <el-header>
                <!-- <span @click="home">Login</span> -->
            <div id="header-left"> <img src="../assets/left.png" alt=""></div>
            <div id="header-right"><img src="../assets/right.png" alt=""></div>
            <el-button type="info" @click="logout" class="back">退出</el-button>
        </el-header>
        <el-container>
            <!--            左边栏-->
            <el-aside :width="isCollapse?'64px' : '200px'">
                <!--                侧边栏菜单区-->
                <div class="toggle-button" @click="toggle">|||</div>
                <el-menu unique-opened background-color="#6d7275" text-color="#fff" active-text-color="#409eff"
                         :collapse="isCollapse" :collapse-transition="false" :router="true"
                         :default-active="activePath">
                    <!--一级菜单-->
                    <el-submenu v-for="item in menuList " :key="item.id" :index="'/'+item.path">
                        <!-- template一级菜单模板区-->
                        <template slot="title">
                            <!-- i  图标-->
                            <i :class="iconsList[item.id]"></i>
                            <!--   span  文本-->
                            <span>{{item.authName}}</span>
                        </template>
                        <!--                        二级菜单-->
                        <el-menu-item v-for="child  in item.childMenus" :key="child.id"
                                      :index="'/'+child.path" @click="save('/'+child.path)">
                            <!--                i            图标-->
                            <i class="el-icon-menu"></i>
                            <!--               span             文本-->
                            <span>{{child.authName}}</span>
                        </el-menu-item>

                    </el-submenu>
                </el-menu>
            </el-aside>
            <!--            中心区域-->

            <el-main>

                <router-view></router-view>
            </el-main>
        </el-container>
    </el-container>
</template>

<script>
    export default {
        name: "Home",
        data() {
            return {
                menuList: [],
                iconsList: {
                    '1': 'el-icon-shopping-bag-1',
                    '2': 'el-icon-s-custom',
                    '3': 'el-icon-s-order',
                    '4': 'el-icon-data-analysis'
                },
                isCollapse: false,
                activePath: '',
            }
        },
        created() {
            this.getMenuList(this.$route.query)
            this.activePath = window.sessionStorage.getItem("activePath")
        },
        methods: {
            logout() {
                window.sessionStorage.clear();
                this.$router.push("/login");
            },
            async getMenuList(type) {
                const result = await this.$http.post('cld/menu',type)
                console.log('-----------',result.data.data)
                if (result.data.code !== 1) {
                    this.$message.error(result.data.message)
                }
                this.menuList = result.data.data
                console.log(result.data.data)
            },
            //菜单的折叠与展开
            toggle() {
                this.isCollapse = !this.isCollapse
            },
            save(activePath) {
                window.sessionStorage.setItem('activePath', activePath)
                this.activePath = activePath;
            },
            home(){
                this.$router.push("/home");
            }
        }
    }
</script>

<style lang="less" scoped>
    .home_container {
        height: 100%;
    }
    #header-left{
        width: 23rem;
        height: 100%;
    }
    #header-left img{
        width: 100%;
        height: 100%;
    }
    #header-right{
        width: 100%;
        height: 100%;
    }
    #header-right img{
        width: 100%;
        height: 100%;
    }
    .el-header {
        // background-image: url('../assets/logo2.png');
        // background-size: 100% 100%;
        display: flex;
        justify-content: space-between;
        align-items: center;
        color: #fff;
        padding: 0 0;
    }

    .el-aside {
        background-color: #6d7275;

        .el-menu {
            border-right: none;
        }
    }

    .el-main {
        background-color: #eaedf1;
    }

    .toggle-button {
        background-color: #6d7275;
        font-size: 10px;
        color: #fff;
        text-align: center;
        letter-spacing: 0.2em;
        cursor: pointer;

    }
    .back{
        position: absolute;
        right: 3rem;
    }
</style>